﻿Imports Microsoft.VisualBasic.Devices

Public Class DownloadabeWallpaper
  Inherits Wallpaper

  Private _url As String
  Private _config As Configuration = Configuration.GetObject

  Public Sub New(ByVal wp As WallpaperService)
    MyBase.New(wp)
  End Sub

  Public Property URL() As String
    Get
      Return _url
    End Get
    Set(ByVal value As String)
      If value.IndexOf("RESOLUTION") > 0 And MyBase.Resolution <> "" Then
        value = value.Replace("RESOLUTION", MyBase.Resolution)
      End If
      _url = value
    End Set
  End Property

  Public Function DownloadFile(Optional ByVal insert As Boolean = True) As Boolean
    Dim n As New Network
    Dim w As Wallpaper
    Try
      n.DownloadFile(URL, _config.SkinsPath & Filename)
    Catch e As IO.IOException
      If MsgBox("Es gab eine Exception vom Typ " & e.ToString() & "." & vbNewLine & "Möchten Sie die Datei Informationen trotzdem in der Datenbank hinterlegen?" & vbNewLine & e.Message, MsgBoxStyle.Information + MsgBoxStyle.YesNo, e.ToString()) = MsgBoxResult.No Then
        End
      End If
    End Try

    MyBase.Datum = Date.Now
    If insert = True Then
      _wp_manager.InsertNewWallpaper(Me)
      w = _wp_manager.GetWallpaperById(Me.ID)
      Me.FullName = w.FullName
    End If
  End Function
End Class
